import * as echarts from 'echarts'

export default function getMyMixin(source: string){
    const getImgUrl = (echartsName: string) => {
        const myChart = echarts.init(document.getElementById(echartsName) as HTMLElement);
        let url =  myChart.getDataURL({
            type: 'png',
            pixelRatio: 15,
            backgroundColor: '#fff'
        })
        return url
    }
    const saveImg = (imgName: string, url: string) => {
        let link = document.createElement('a');
        link.style.display = 'none'
        link.href = url
        // 获取文件名
        // download 属性定义了下载链接的地址而不是跳转路径
        link.setAttribute('download', imgName)
        document.body.appendChild(link)
        link.click()
        link.remove()
    }
    const saveCSV = (csvName: string, content: Blob) => {
        let urlObject = window.URL || window.webkitURL || window;
        let url = urlObject.createObjectURL(content);
        let el = document.createElement("a");
        el.href = url;
        el.download = csvName+".csv";
        el.click();
        urlObject.revokeObjectURL(url);
    }
    return{
        getImgUrl,
        saveImg,
        saveCSV
    }
}